<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="../../lib/layui-v2.6.3/css/layui.css" media="all" rel="stylesheet">
    <link href="../../css/public.css" media="all" rel="stylesheet">
    <link href="../../css/diy/form1.css" rel="stylesheet">
    <script src="../../lib/layui-v2.6.3/layui.js"></script>
    <script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <script src="../../js/template-web.js"></script>
    <script src="../../js/lay-module/layuimini/miniTab.js"></script>
    <script src="../../frontstatic/js/notify.js"></script>
    <script src="../../frontstatic/js/notify_stand.js"></script>
</head>
<body>
<div id="KindHeader">
    <div>
        <img height="25" loading="lazy" src="../../images/table.png" width="25">
        <span>商品种类列表</span>
        <form class="layui-form" style="padding-top: 30px" action="" lay-filter="example">
            <div class="layui-inline">
                <label class="layui-form-label">类别名称：</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" class="layui-input" name="commtityName" placeholder="请输入" type="text">
                </div>
            </div>
            <div class="layui-form-item" style="position: relative;left: -50px" id="selectBtn">
                <div class="layui-input-block">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button class="layui-btn layui-btn-normal" id="selectwhereBtn" type="button">查询
                </button>
                    <button class="layui-btn layui-btn-primary  layui-btn-sm" type="reset">重置</button>
                </div>
            </div>

        </form>
        <button class="layui-btn layui-btn-primary layui-btn-sm " style="position: relative;left: 600px;top: 20px" id="KindaddBtn">添加</button>
    </div>
    <div style="background-color: #FFFFFF; border-radius: 15px;margin-top: 40px;width: 1550px">
        <table class="layui-table" id="kindTable" lay-filter="demo"></table>
    </div>
</div>
<script id="barDemo" type="text/html">
    <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    var notify;
    layui.use(['notify'],function(){
        notify=layui.notify;
    })
    layui.use(['table','form'], function () {
        var table = layui.table;
        var form=layui.form;
        var miniTab = layui.miniTab;
        var tableIns = table.render({
            elem: '#kindTable'
            , method: 'post'
            , title: '商品类别表'
            , url: '/kind/page' //数据接口
            , page: {theme: '#1E9FFF'} //开启分页
            , limit:10
            , even: true
            ,toolbar:true
            ,defaultToolbar: ['filter', 'exports',{
                title: '商品数据表'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,request: {
                pageName: 'curr' //页码的参数名称，默认：page
                ,limitName: 'nums' //每页数据量的参数名，默认：limit
            }
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records//解析数据列表
                };
            }
            , cols: [[
                //表头
                {type: 'numbers', title: '序号'}
                , {field: 'name', title: '类别名称'}
                , {field: 'upname', title: '上一级种类名称'}
                , {field: 'isRank', title: '商品种类等级'}
                , {field: 'createTime', title: '创建时间'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo'}
            ]]
        });
        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'sele') {
                $.get("/deposit", {"id": data.id}, function () {
                    miniTab.openNewTabByIframe({
                        href: "page/commodity/kind_commodityData.html",
                        title: data.k_name + "类别下的商品数据",
                    });
                })
            } else if (obj.event === 'del') {
                layer.confirm('真的删除该商品类别吗？', function (index) {
                    $.get("/kind/delete", {"id": data.id}, function (ex) {
                        if (ex.code==0) {
                            obj.del();
                            notify.success(ex.msg)
                        } else{
                            notify.error(ex.msg)
                        }
                    })
                });
            } else if (obj.event === 'edit') {
                layer.alert('编辑行：<br>' + JSON.stringify(data))
            }
        });
        $("#KindaddBtn").on('click', function () {
            miniTab.openNewTabByIframe({
                href: "page/commodity/kindAdd.html",
                title: "种类添加",
            });
        })
        $("#selectwhereBtn").on('click', function() {
            var data = form.val('example');
            var orderDate = {
                "name": data.commtityName,
            }
            tableIns.reload({
                where:orderDate
                ,page: {
                    curr: 1
                }
            });
        })
    })
</script>
</body>
</html>